package com.hanggold.endpoint.filter;

import org.apache.catalina.core.ApplicationFilterRegistration;
import org.springframework.boot.web.servlet.DynamicRegistrationBean;

import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2019-07-25 15:31
 * @since
 **/
public class FilterBeanRegister extends DynamicRegistrationBean<FilterRegistration.Dynamic> {

    private Filter filter;

    public FilterBeanRegister(Filter filter) {
        this.filter = filter;
    }

    @Override
    protected FilterRegistration.Dynamic addRegistration(String description, ServletContext servletContext) {
        ApplicationFilterRegistration applicationFilterRegistration = (ApplicationFilterRegistration) servletContext.addFilter("filter",
                this.filter);

        return applicationFilterRegistration;
    }

    @Override
    protected String getDescription() {
        return "自定义fule";
    }
}
